﻿using SCS.Common.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SCS.DAL
{
    public class CommentRepository : Repository<CommentInClass>, ICommentRepository
    {
        public CommentRepository(SCSContext _context)
            : base(_context)
        { }


        public int GetCount()
        {
            return DBSet.Count();
        }

        /// <summary>
        /// Get count of search result
        /// </summary>
        /// <param name="firstDate">from date</param>
        /// <param name="lastDate">to date</param>
        /// <returns>Count of search result</returns>
        public int GetSearchCount(DateTime firstDate, DateTime lastDate)
        {
            return DBSet.Where(s => s.dateOfComment <= lastDate).Where(s => s.dateOfComment >= firstDate).Count();
        }

        /// <summary>
        /// Search Comment In Time Paging
        /// </summary>
        /// <param name="pageNumber">Number of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <param name="firstDate">from date</param>
        /// <param name="lastDate">to date</param>
        /// <param name="learnerID">learner ID</param>
        /// <returns>List Comment</returns>
        public IList<CommentInClass> SearchGradeInTimePaging(int pageNumber, int pageSize, DateTime firstDate, DateTime lastDate)
        {
            return DBSet.Where(s => s.dateOfComment <= lastDate).Where(s => s.dateOfComment >= firstDate).OrderBy(x => x.dateOfComment)
         .Skip((pageNumber - 1) * pageSize)
         .Take(pageSize)
         .ToList();
        }

        /// <summary>
        /// Search Comment In Time Paging
        /// </summary>
        /// <param name="pageNumber">Number of page</param>
        /// <param name="pageSize">Size of page</param>
        /// <param name="firstDate">from date</param>
        /// <param name="lastDate">to date</param>
        /// <param name="learnerID">learner ID</param>
        /// <returns>List Comment</returns>
        public IList<CommentInClass> SearchGradeInTimePaging(int pageNumber, int pageSize, DateTime firstDate, DateTime lastDate, int learnerID)
        {
            return DBSet.Where(s => s.dateOfComment <= lastDate && s.dateOfComment >= firstDate && s.learnerID == learnerID).OrderByDescending(x => x.dateOfComment)
         .Skip((pageNumber - 1) * pageSize)
         .Take(pageSize)
         .ToList();
        }
    }
}